//联合类型
let test: string | number;

test =1;

test = "Hello";

//联合类型数组
const arr: (string | number)[] = [1, 2, 3, 4, 5, "hello"];

arr.forEach((item) => {
  if (typeof item === "string") {
    console.log("安全调用string 方法", item.toUpperCase());
  } else if (typeof item === "number") {
    console.log("安全调用number 方法", item.toFixed(2));
  }
});
